package de.fuberlin.inf.alp4.ue2;

import java.util.Random;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class Proxy {
	
	public Scheduler scheduler;
	
	public Proxy() {
		this.scheduler = new Scheduler();
	}
	
	public void put(MethodRequest request) throws Exception {
		if(!this.scheduler.enqueue(request))
			throw new Exception("Could not enqueue the current MessageRequest");		
	}
	
	/**
	 * constructs a new MethodRequest Object.
	 * A MethodRequest must include a valid Future instance which will be generated in this method.
	 * @return this MethodRequest's Future instance
	 * @throws EnqueueException if the MethodRequest could not be enqueued
	 */
	public MyFuture newMethodRequest() throws Exception {
		Random r = new Random();
		MethodRequest request = new MethodRequest(r.nextInt()%10, r.nextInt()%20);
		MyFuture future = new MyFuture(request);
		this.put(request);
		return future;
	}
	
}
